package com.gljr.exam.dao;

import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
import org.springframework.transaction.annotation.Transactional;

import com.gljr.exam.domain.User;

public interface UserRepository extends PagingAndSortingRepository<User, Long> {

	User findByUsernameIgnoreCase(String username);

	@Query("SELECT admin FROM User WHERE username = ?1")
	Boolean getIfAdmin(String username);

	@Query("SELECT userexamstatus FROM User WHERE username = ?1")
	Boolean getIfUserExamStatus(String username);

	@Modifying
	@Transactional
	@Query("UPDATE User SET userexamstatus = ?2  WHERE username = ?1")
	void setUserExamStatus(String username, Boolean b);

	@Modifying
	@Transactional
	@Query("UPDATE User SET password = ?2  WHERE username = ?1")
	void updatePSW(String username, String password);
}
